import {Component, inject} from '@angular/core';
import {Router} from "@angular/router";
import {StudyShareModule} from "../../StudyShareModule";

@Component({
  selector: 'app-login',
  standalone: true,
  imports: [StudyShareModule],
  templateUrl: './login.component.html',
  styleUrls: []
})
export class LoginComponent {
  authService: AuthService = inject(AuthService);
  router: Router = inject(Router)
  user = {
    username: '',
    pwd: ''
  };
  message: string = ''

  constructor() {
  }

  login() {
    const redirectUrl = pathConstant.path.commentList;
    // console.log(JSON.stringify(this.user))
    console.log(this.authService)
    this.authService.login(this.user).subscribe(() => {
      if (this.authService.isLogin()) {
        this.router.navigate([redirectUrl]);
      }
    });
  }


  logout() {
    this.authService.logout();
    this.message = this.getMessage();
  }

  getMessage() {
    return 'Logged ' + (this.authService.isLogin() ? 'in' : 'out');
  }
}
